/**
 * 
 */
package com.feib.stms.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.feib.stms.dao.UploadFileTodoListDao;
import com.feib.stms.model.MenuItem;
import com.feib.stms.model.UploadFile;
import com.feib.stms.model.UploadFileTodoList;
import com.feib.stms.model.User;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.UploadFileTodoListService;

/**
 * @author Jeff Gu
 *
 */
@Service("uploadFileTodoListService")
public class UploadFileTodoListServiceImpl extends BaseServiceImpl implements UploadFileTodoListService{


	private static final long serialVersionUID = -7954356715884053158L;
	
	@Resource(name="uploadFileTodoListDao")
    private UploadFileTodoListDao uploadFileTodoListDao;
	

	public int addUploadFileTodoList(UploadFile uploadFile) {
		Long checkMenuItemPk = null;
		Long confirmMenuItemPk = null;
		if (UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			// 交割款資料檔
			checkMenuItemPk = new Long(12); // 交割款資料審查
			confirmMenuItemPk = new Long(13); // 交割款資料放行
		}
		else if (UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT_CHK.equals(uploadFile.getFileFormat()))
		{
			// 交割款驗資檔 , do nothing.
		}
		else if (UploadFile.UPLOAD_FILE_PURCHASE_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			// 申購款資料檔 
			checkMenuItemPk = new Long(18); // 申購款資料審查
			confirmMenuItemPk = new Long(19); // 申購款資料放行
		}
		else if (UploadFile.UPLOAD_FILE_PURCHASE_RETURN_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			// 申購退款資料檔
			checkMenuItemPk = new Long(24); // 申購退款資料審查
			confirmMenuItemPk = new Long(25); // 申購退款資料放行
		}
		
		UploadFileTodoList todoList = new UploadFileTodoList();
		todoList.setUploadFile(uploadFile);
		todoList.setSecuritiesNo(uploadFile.getSecuritiesNo());
		todoList.setGroup(uploadFile.getGroup());
		if (null != checkMenuItemPk && null != uploadFile.getCheckCount() && 0 < uploadFile.getCheckCount().intValue())
		{
			// 須要審查
			MenuItem menuItem = new MenuItem();
			menuItem.setMenuItemPk(checkMenuItemPk);
			todoList.setMenuItem(menuItem);
			return uploadFileTodoListDao.addUploadFileTodoList(todoList);
		}
		else if (null != confirmMenuItemPk && null != uploadFile.getConfirmCount() && 0 < uploadFile.getConfirmCount().intValue())
		{
			// 須要放行
			MenuItem menuItem = new MenuItem();
			menuItem.setMenuItemPk(confirmMenuItemPk);
			todoList.setMenuItem(menuItem);
			return uploadFileTodoListDao.addUploadFileTodoList(todoList);
		}
		
		return 0;
		
	}

	public PaginatedList<UploadFileTodoList> findUploadFileTodoList(User user, PaginatedList paginatedList) {
		
		return uploadFileTodoListDao.queryUploadFileTodoList(user, paginatedList);
	}

}
